<?php
/**
 * @version		$Id: kendo.php 1 2012-02-25 17:10:28Z grigor.mihov $
 * @package		Kendo Plugin
 * @author		StyleWare http://www.styleware.eu
 * @copyright	Copyright (c) 2012 StyleWare Ltd. All rights reserved. Source by Telerik Kendo Project under GPL3 license.
 * @source		http://kendoui.com - Kendo UI by Telerik (http://www.telerik.com/)
 * @license		GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
 */

// no direct access
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.form.form' );
jimport( 'joomla.html.parameter' );
jimport('joomla.plugin.plugin');

class plgSystemKendo extends JPlugin {

	function plgSystemKendo(&$subject, $config) {
		parent::__construct($subject, $config);
		$this->loadLanguage('plg_system_kendo');
	}

	function onAfterRoute() {
		$mainframe = JFactory::getApplication();
		$document = JFactory::getDocument();
	
		// Load in admin, disabled by default
		if(($this->params->get('kadmin',0))==1) {
			if ($mainframe->isAdmin()) {
				return;
			}		
		}
		
		// Load jQuery, enabled by default
		if(($this->params->get('kjquery',1))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/jquery.min.js');
		}		
		
		// Load jQuery Templates, enabled by default
		if(($this->params->get('kjquerytemplates',1))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/jquery.tmpl.min.js');
		}
		
		// Load All Libraries, enabled by default
		if(($this->params->get('kall',1))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.all.min.js');
		}
		
		// Load Common Kendo CSS, enabled by default
		if(($this->params->get('kcommon',1))==1) {
			$document->addStyleSheet(JURI::root(true).'/plugins/system/kendo/styles/kendo.common.min.css',"text/css","screen");
		}
		
		// Load Common Kendo CSS, enabled by default
		if(($this->params->get('kcommon',1))==1) {
			$document->addStyleSheet(JURI::root(true).'/plugins/system/kendo/styles/kendo.common.min.css',"text/css","screen");
		}
		// Load the UI Theme, enabled by default to load the Default theme
		if(($this->params->get('ktheme',1))>0) {
			$ktheme='';
			if(($this->params->get('ktheme'))==1) {
			$ktheme='default';
			}
			if(($this->params->get('ktheme'))==2) {
			$ktheme='black';
			}			
			if(($this->params->get('ktheme'))==3) {
			$ktheme='blueopal';
			}
			if(($this->params->get('ktheme'))==4) {
			$ktheme='hakama';
			}
			if(($this->params->get('ktheme'))==5) {
			$ktheme='kendo';
			}
			if(($this->params->get('ktheme'))==6) {
			$ktheme='metro';
			}
			if(($this->params->get('ktheme'))==7) {
			$ktheme='silver';
			}
			$document->addStyleSheet(JURI::root(true).'/plugins/system/kendo/styles/kendo.'.$ktheme.'.min.css',"text/css","screen");
		}
		
		// End the Block with General Options and start localizations

		// Load Localization 1, disabled by default
		if(($this->params->get('klang1'))!="" & ($this->params->get('klang1'))!="-1" ) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/culture/'.$this->params->get('klang1').'');
		}				

		// Load Localization 2, disabled by default
		if(($this->params->get('klang2'))!="" & ($this->params->get('klang2'))!="-1" ) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/culture/'.$this->params->get('klang2').'');
		}				
		
		// Load Localization 3, disabled by default
		if(($this->params->get('klang3'))!="" & ($this->params->get('klang3'))!="-1" ) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/culture/'.$this->params->get('klang3').'');
		}				
		
		// Load Localization 4, disabled by default
		if(($this->params->get('klang4'))!="" & ($this->params->get('klang4'))!="-1" ) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/culture/'.$this->params->get('klang4').'');
		}				
		
		// Load Localization 5, disabled by default
		if(($this->params->get('klang5'))!="" & ($this->params->get('klang5'))!="-1" ) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/culture/'.$this->params->get('klang5').'');
		}				

		
		// Everything essential should be loaded if we load all the scripts (kendo.all.min.js) - next we kill the load of individual files
		
		// Kill the rest to not load any additional files
		if(($this->params->get('kall',1))==1) {
			return;
		}
		
		// End the Block with localizations and start individual JS files (killed if all are enabled)
		
		// Load Autocomplete, disabled by default
		if(($this->params->get('kautocomplete',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.autocomplete.min.js');
		}		
		
		// Load Binder, disabled by default
		if(($this->params->get('kbinder',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.binder.min.js');
		}		

		// Load Calendar, disabled by default
		if(($this->params->get('kcalendar',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.calendar.min.js');
		}		

		// Load Chart, disabled by default
		if(($this->params->get('kchart',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.chart.min.js');
		}				

		// Load Combobox, disabled by default
		if(($this->params->get('kcombobox',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.combobox.min.js');
		}				

		// Load Core, disabled by default
		if(($this->params->get('kcore',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.core.min.js');
		}				

		// Load Data, disabled by default
		if(($this->params->get('kdata',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.kdata.min.js');
		}				

		// Load Data OData, disabled by default
		if(($this->params->get('kdataodata',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.data.odata.min.js');
		}				

		// Load Data XML, disabled by default
		if(($this->params->get('kdataxml',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.data.xml.min.js');
		}				

		// Load Dataviz, disabled by default
		if(($this->params->get('kdataviz',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.dataviz.min.js');
		}				

		// Load Date Picker, disabled by default
		if(($this->params->get('kdatepicker',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.datepicker.min.js');
		}				

		// Load Drag and Drop, disabled by default
		if(($this->params->get('kdraganddrop',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.draganddrop.min.js');
		}				

		// Load Drop Down List, disabled by default
		if(($this->params->get('kdropdownlist',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.dropdownlist.min.js');
		}				

		// Load Editable, disabled by default
		if(($this->params->get('keditable',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.editable.min.js');
		}				

		// Load Filter Menu, disabled by default
		if(($this->params->get('kfiltermenu',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.filtermenu.min.js');
		}				

		// Load FX, disabled by default
		if(($this->params->get('kfx',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.fx.min.js');
		}				

		// Load Grid, disabled by default
		if(($this->params->get('kgrid',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.grid.min.js');
		}				

		// Load Groupable, disabled by default
		if(($this->params->get('kgroupable',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.groupable.min.js');
		}				

		// Load List, disabled by default
		if(($this->params->get('klist',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.list.min.js');
		}				

		// Load Menu, disabled by default
		if(($this->params->get('kmenu',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.menu.min.js');
		}				

		// Load Model, disabled by default
		if(($this->params->get('kmodel',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.model.min.js');
		}				

		// Load Numeric Text Box, disabled by default
		if(($this->params->get('knumerictextbox',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.numerictextbox.min.js');
		}				

		// Load Panel bar, disabled by default
		if(($this->params->get('kpanelbar',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.panelbar.min.js');
		}				

		// Load Popup, disabled by default
		if(($this->params->get('kpopup',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.popup.min.js');
		}				

		// Load Resizable, disabled by default
		if(($this->params->get('kresizable',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.resizable.min.js');
		}				

		// Load Selectable, disabled by default
		if(($this->params->get('kselectable',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.selectable.min.js');
		}				

		// Load Slider, disabled by default
		if(($this->params->get('kslider',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.slider.min.js');
		}				

		// Load Sortable, disabled by default
		if(($this->params->get('ksortable',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.sortable.min.js');
		}				

		// Load Splitter, disabled by default
		if(($this->params->get('ksplitter',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.splitter.min.js');
		}				

		// Load Tab Strip, disabled by default
		if(($this->params->get('ktabstrip',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.tabstrip.min.js');
		}				

		// Load Time Picker, disabled by default
		if(($this->params->get('ktimepicker',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.timepicker.min.js');
		}				

		// Load Tree View, disabled by default
		if(($this->params->get('ktreeview',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.treeview.min.js');
		}				

		// Load Upload, disabled by default
		if(($this->params->get('kupload',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.upload.min.js');
		}				

		// Load Validator, disabled by default
		if(($this->params->get('kvalidator',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.validator.min.js');
		}				

		// Load Web, disabled by default
		if(($this->params->get('kweb',0))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.web.min.js');
		}				

		// Load Window, disabled by default
		if(($this->params->get('kwindow',1))==1) {
			$document->addScript(JURI::root(true).'/plugins/system/kendo/js/kendo.window.min.js');
		}
		
	}

}